﻿<cfsilent>
	<cfscript>

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		propertyAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		subjectId = event.getArg('SubID');
		
		/* 当前在校生判断 grade + schooling_length > ? */
		gradeLeast = year( now() );
		if ( month( now() ) < 9 ) {
			gradeLeast = year( now() ) - 1;
		}
		
		/* 读取专业信息 */
		sql = "SELECT 
				sbj_name, t_institute.institute_id, t_institute.institute_name 
				FROM t_subject 
				INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					sbj_id = :subjectId ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype = "cf_sql_varchar");

		rs_subject = queryObj.execute( sql=sql ).getResult();


		event.setArg("pageTitle", "教学运行基础数据 - 学生学籍 - 专业成绩状态 - " & rs_subject.sbj_name);
		
		
		/* 学院年级列表 */
		sql = "SELECT 
				a.grade, COUNT(a.cls_id) class_count, SUM(a.cls_size) plan_size, SUM(a.cls_scale) real_size 
				FROM t_class a 
				INNER JOIN t_subject b ON b.sbj_id = a.sbj_id 
				WHERE 
					b.sbj_id = :subjectId 
					AND 
					a.grade + b.schooling_length > :yearNow 
				GROUP BY a.grade 
				ORDER BY a.grade DESC ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype = "cf_sql_varchar");
		queryObj.addParam( name="yearNow", value=gradeLeast, cfsqltype="cf_sql_integer" );

		rs_grade = queryObj.execute( sql=sql ).getResult();
		
		
		/* 学院专业列表 */
		sql = "SELECT 
				b.sbj_id, b.sbj_name, b.term_start, b.level_code, COUNT(cls_id) class_count 
				FROM t_class a 
				INNER JOIN t_subject b ON b.sbj_id = a.sbj_id 
				WHERE 
					b.institute_id = :depId 
					AND 
					a.grade + b.schooling_length > :yearNow 
				GROUP BY 
					b.sbj_id, b.sbj_name, b.term_start, b.level_code 
				ORDER BY b.sbj_name ";
					
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="depId", value=depId, cfsqltype = "cf_sql_varchar");
		queryObj.addParam( name="yearNow", value=gradeLeast, cfsqltype="cf_sql_integer" );

		rs_subject_by_dep = queryObj.execute( sql=sql ).getResult();
		
		
		/* 学生成绩分段统计 */
		sql = "SELECT 
				grade, 
				sum_lt60, sum_gte60_lt70, sum_gte70_lt80, sum_gte80_lt90, sum_gte90 
				FROM mv_sbj_grade_mark_status 
				WHERE 
					institute_id = :depId 
					AND 
					sbj_id = :subjectId 
				ORDER BY grade ";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="depId", value=depId, cfsqltype = "cf_sql_varchar");
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype = "cf_sql_varchar");

		rs_scroll = queryObj.execute( sql=sql ).getResult();
		
		
		currentTab = event.getArg("TabID", "labSubject");
		
		targetArgs = structNew();
		structInsert(targetArgs, "SubID", subjectId, true);
		structInsert(targetArgs, "DepID", depId, true);
		
		passArgs = structNew();
		structInsert(passArgs, "SubID", subjectId, true);
		structInsert(targetArgs, "DepID", depId, true);
		
		/* 搜索学生档案 */
		keyword = event.getArg("Keywords");
		
		rs_student = queryNew("stu_id, stu_name, cls_name, stu_prop");
		
		if ( len(keyword) ) {
			
			sql = "SELECT 
					a.stu_id, a.stu_name, 
					b.cls_name, 
					d.student_prop 
					FROM t_student a 
					INNER JOIN t_class b ON b.cls_id = a.cls_id 
					INNER JOIN t_subject c ON c.sbj_id = b.sbj_id AND c.institute_id = :depId 
					INNER JOIN t_student_status d ON d.stu_id = a.stu_id 
					WHERE 
						a.stu_id LIKE :condition 
						OR 
						a.stu_name LIKE :condition 
					ORDER BY 
						a.stu_name";
			
			queryObj = new Query( datasource=application.dnsSlave, maxRows=60 );
			queryObj.addParam( name="depId", value=depId, cfsqltype = "cf_sql_varchar");
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype = "cf_sql_varchar");

			rs_student = queryObj.execute( sql=sql ).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('studentMark')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">学生成绩</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_subject.sbj_name#</cfoutput>专业成绩分布
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSubject">class="active"</cfif> id="labSubject" tabTarget="Subject">年级分布状态</span>
						<cfloop query="rs_grade">
							<span <cfif currentTab eq "labGrade" & rs_grade.grade>class="active"</cfif> id="labGrade<cfoutput>#rs_grade.grade#</cfoutput>" tabTarget="Grade<cfoutput>#rs_grade.grade#</cfoutput>"><cfoutput>#rs_grade.grade#</cfoutput></span>
						</cfloop>
						<span <cfif currentTab eq "labSubjectOther">class="active"</cfif> id="labSubjectOther" tabTarget="SubjectOther">其他专业</span>
						
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索学生成绩</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Subject" class="tabContent">
					
					<div class="noticeBlock">
						<h3><cfoutput>#rs_subject.sbj_name#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>从上方选择对应年级查看该行政班学生成绩</p>
						<hr/>
					</div>
					
					<div class="clearfix mbl"></div>
					<div id="container" style="height: <cfoutput>#(100 + rs_scroll.recordCount * 50)#</cfoutput>px;"></div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						var chart;
						
						$(document).ready(function() {
							
							chart = new Highcharts.Chart({
								chart: {
									renderTo: 'container', 
									type: 'bar'
									},
								colors: ['#ff8c05','#fdd283','#43a102','#a2b700','#c5da01'],
								title: {
									text: '<cfoutput>#rs_subject.sbj_name#</cfoutput>专业'
									},
								subtitle: {
									text: '各年级学生成绩分布统计示意图'
									},
								xAxis: {
									categories: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ />'<cfoutput>#rs_scroll["grade"][a]#</cfoutput>'<cfif a lt rs_scroll.recordCount>,</cfif></cfloop>],
									labels: {
										style : {
											'font-size': '12px', 
											'font-family': 'SimSun'
											}
										}
									},
								legend: {
									itemStyle : {
											'font-size': '10px'
											}
								},
								yAxis: {
									title: {
										text: null
										}
									},
								tooltip: {
									formatter: function() {
										return this.x + ' 级<br/>'+ this.series.name +': '+ '成绩比例为' +' ('+ Math.round(this.percentage) +'%)';
										}
									},
								credits: {
									enabled: false
									},
								plotOptions: {
									bar: {
										stacking: 'percent'
										}
									},
								series: [{
									name: '0-60',
									data: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ /><cfoutput>#rs_scroll["sum_lt60"][a]#</cfoutput><cfif a lt rs_scroll.recordCount>,</cfif></cfloop>]
									}, 
									{
									name: '60-70',
									data: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ /><cfoutput>#rs_scroll["sum_gte60_lt70"][a]#</cfoutput><cfif a lt rs_scroll.recordCount>,</cfif></cfloop>]
									}, 
									{
									name: '70-80',
									data: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ /><cfoutput>#rs_scroll["sum_gte70_lt80"][a]#</cfoutput><cfif a lt rs_scroll.recordCount>,</cfif></cfloop>]
									}, 
									{

									name: '80-90',
									data: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ /><cfoutput>#rs_scroll["sum_gte80_lt90"][a]#</cfoutput><cfif a lt rs_scroll.recordCount>,</cfif></cfloop>]
									}, 
									{
									name: '90+',
									data: [<cfset a = 0 /><cfloop query="rs_scroll"><cfset a++ /><cfoutput>#rs_scroll["sum_gte90"][a]#</cfoutput><cfif a lt rs_scroll.recordCount>,</cfif></cfloop>]
									}]
									
							});
							
						});
					
						// -->
						//]]>
					</script>
					
				</div>
				
				<cfloop query="rs_grade">
					

					<cfscript>
						
						gradeId = rs_grade.grade;
						
						structInsert(passArgs, "Grade", gradeId, true);
						structInsert(passArgs, "SubID", subjectId, true);
						
						sql = "SELECT 
								cls_id, cls_name, cls_size, cls_scale, t_campus.campus_name 
								FROM t_class 
								INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id 
								WHERE grade = :gradeId AND sbj_id = :subjectId ";
						
						queryObj = new Query( datasource=application.dnsSlave );
						queryObj.addParam( name="gradeId", value=gradeId, cfsqltype = "cf_sql_char");
						queryObj.addParam( name="subjectId", value=subjectId, cfsqltype = "cf_sql_varchar");
						
						rs_class = queryObj.execute( sql=sql ).getResult();
						
					</cfscript>
					
					<div id="Grade<cfoutput>#gradeId#</cfoutput>" class="tabContent">
						<div class="noticeBlock">
							<div class="operation">
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('subjectMarkPassPrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印专业通过课程成绩单</span></a>
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('subjectMarkPrint', passArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印专业成绩单</span></a>
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentMarkListBySubjectGradeDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载专业成绩</span></a>
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentMarkBySubjectGradeDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载专业学分和统计排名</span></a>
							</div>
							<h3><cfoutput>#gradeId#</cfoutput>级</h3>
							<p><span class="img icon16x16 message"></span>共计<em><cfoutput>#rs_grade.class_count#</cfoutput></em>个行政班, 计划招生规模<em><cfoutput>#rs_grade.plan_size#</cfoutput></em>人, 实际学生人数<em><cfoutput>#rs_grade.real_size#</cfoutput></em>.</p>
							<hr/>
						</div>

						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>班级</td>
									<td width="80">所在校区</td>
									<td width="60" align="center">计划人数</td>
									<td width="40" align="center">学生数</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfloop query="rs_class" >
									<cfset structInsert(targetArgs, "Class", rs_class.cls_id, true) />
									<cfset row++ />
									<tr class="editRows <cfif rs_class.cls_size lt rs_class.cls_scale>noticeRow1</cfif>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_class.cls_name#</cfoutput></td>
										<td><cfoutput>#rs_class.campus_name#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_class.cls_size#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_class.cls_scale#</cfoutput></span></td>
										<td><a class="stat info" href="<cfoutput>#buildURL('studentMarkByClass', targetArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
				</cfloop>
				
				<div id="SubjectOther" class="tabContent">
					
					<cfset structDelete(targetArgs, "Class") />
					
					<div class="noticeBlock">
						<h3><cfoutput>#rs_subject.institute_name#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>共计<em><cfoutput>#rs_subject_by_dep.recordCount#</cfoutput></em>个招生专业, 点击专业名称查看行政班分布情况</p>
						<hr/>
					</div>
					
					<div class="clearfix">
						<div class="UICardTable">
							<cfloop query="rs_subject_by_dep">
								<cfset structInsert(targetArgs, "SubID", rs_subject_by_dep.sbj_id, true) />
								<dl>
									<dt>
										<a href="<cfoutput>#buildURL('studentMarkBySubject', targetArgs)#</cfoutput>">
											<em class="subject"><!--imgholder--></em>
											<dd>
												<h3><cfoutput>#rs_subject_by_dep.sbj_name#</cfoutput></h3>
												<div><cfoutput>#dictAdvice.getTermEnrol( rs_subject_by_dep.term_start )#-#dictAdvice.getStudentLevel( rs_subject_by_dep.level_code )#-#rs_subject_by_dep.class_count#个行政班</cfoutput></div>
											</dd>
										</a>
									</dt>
								</dl>
							</cfloop>
						</div>
					</div>

				</div>
				
				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('studentMarkBySubject')#</cfoutput>">
						<input type="hidden" name="TabID" value="labSearch" />
						<input type="hidden" name="SubID" value="<cfoutput>#subjectId#</cfoutput>" />
						<input type="hidden" name="DepID" value="<cfoutput>#depId#</cfoutput>" />
						
						<div class="label">
							<b>学号或姓名</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
					<cfif rs_student.recordCount >
						
						<div class="clearfix">
							<div class="UICardTable">
								<cfloop query="rs_student">
									
									<cfset structInsert(passArgs, "STU", rs_student.stu_id, true) />
									<cfset propertyAdvice.parseProperty( rs_student.student_prop ) />
									
									<dl <cfif not propertyAdvice.getInSchool()>class="disabled"</cfif>>
										<dt>
											<a href="<cfoutput>#buildURL('studentMarkView', passArgs)#</cfoutput>">
												<em class="people"><!--imgholder--></em>
												<dd>
													<h3><cfoutput>#rs_student.stu_name#</cfoutput> - <cfoutput>#rs_student.cls_name#</cfoutput></h3>
													<p><cfoutput>#rs_student.stu_id#</cfoutput></p>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>					
							</div>
						</div>
						
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>